package com.hayrullah.cinema.Dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.hayrullah.cinema.Util.HibernateUtil;
import com.hayrullah.cinema.entity.Movie;
@SuppressWarnings("unchecked")
public class MovieDao extends AbstractDao<Movie> {

	@Override
	public Movie findById(Long id) {
		Movie movie=null;
		try {
			Session session =HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			movie=(Movie) session.get(Movie.class, id);
			session.getTransaction().commit();
		} catch (HibernateException  exception) {
			exception.printStackTrace();
		}
		
		return movie;
	}
	
	@Override
	public List<Movie> findAll() {
		List<Movie> movies =null;
		try {
			Session session =HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			movies= (List<Movie>)(session.createCriteria(Movie.class)).list();
			session.getTransaction().commit();
		} catch (HibernateException exception) {
             exception.printStackTrace();
		}
		return movies;
	}
	
	

	
	

}
